package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.config.ObjectUtil;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.common.UpDownMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {
    @Override
    public boolean updateArticleEnable(UpDownMsg upDownMsg) {
        //判断id的条件
        if (ObjectUtil.isEmpty(upDownMsg.getArticleId())) {
            log.error("文章的id为空，无法进行查询");
        }
        //构建更新的条件
        LambdaUpdateWrapper<ApArticleConfig> updateWrapper = Wrappers.<ApArticleConfig>lambdaUpdate()
                .eq(ApArticleConfig::getArticleId, upDownMsg.getArticleId())
                .set(ApArticleConfig::getIsDown, ObjectUtil.equals(upDownMsg.getEnable(), (short) 0));
        //进行更新操作
        return super.update(updateWrapper);
    }
}
